package com.mybatis.mapper;

import com.mybatis.dto.MyEntityDto;
import com.mybatis.dto.MyPrimaryKeyDto;
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator;
import org.apache.ibatis.executor.keygen.KeyGenerator;
import org.apache.ibatis.executor.keygen.NoKeyGenerator;

import javax.persistence.GenerationType;

public class MyKeyGeneratorParameter {
    private KeyGenerator keyGenerator = new NoKeyGenerator();//默认没有自增长，更改数据库都要传
    private String keyProperty;
    private String keyColumn;

    public MyKeyGeneratorParameter(MyEntityDto entityDto) {
        MyPrimaryKeyDto primartDto = entityDto.getMyPrimaryKeyDto();
        if (null!= primartDto)
        {
            this.keyProperty = primartDto.getPropertyName();
            this.keyColumn = primartDto.getCloumnName();
            if (null!=primartDto.getGenerationType()&&primartDto.getGenerationType()== GenerationType.AUTO)
            {
                this.keyGenerator = new Jdbc3KeyGenerator();//mysql独有的自增长主键
            }
        }
    }

    public KeyGenerator getKeyGenerator() {
        return keyGenerator;
    }


    public String getKeyProperty() {
        return keyProperty;
    }


    public String getKeyColumn() {
        return keyColumn;
    }

}
